﻿$.extend($.fn.datagrid.defaults, {
    iconCls: 'fa fa-plus', rownumbers: true,
    animate: true,
    collapsible: true,
    fitColumns: true,
    fit: true,
    pagination: true,
    pageSize: 20,
    pageList: [10, 20, 50, 100],  
});

$.extend($.fn.treegrid.defaults, {
    iconCls: 'fa fa-plus',
    rownumbers: true,
    animate: true,
    collapsible: true,
    fitColumns: true,
    fit: true,
    showFooter: false
});
/**
 * 扩展tree，使其支持平滑数据格式
 */
$.fn.tree.defaults.loadFilter = function (data, parent) {
    var opt = $(this).data().tree.options;
    var idFiled, textFiled, parentField, iconCls;
    if (opt.parentField) {
        idFiled = opt.idFiled || 'id';
        textFiled = opt.textFiled || 'text';
        parentField = opt.parentField;
        iconCls = opt.iconCls || 'iconCls';
        var i, l, treeData = [],
			tmpMap = [];
        for (i = 0, l = data.length; i < l; i++) {
            tmpMap[data[i][idFiled]] = data[i];
        }
        for (i = 0, l = data.length; i < l; i++) {
            if (tmpMap[data[i][parentField]] && data[i][idFiled] != data[i][parentField]) {
                if (!tmpMap[data[i][parentField]]['children'])
                    tmpMap[data[i][parentField]]['children'] = [];
                data[i]['text'] = data[i][textFiled];
                data[i]['iconCls'] = data[i][iconCls];
                tmpMap[data[i][parentField]]['children'].push(data[i]);
            } else {
                data[i]['text'] = data[i][textFiled];
                data[i]['iconCls'] = data[i][iconCls];
                treeData.push(data[i]);
            }
        }
        return treeData;
    }
    return data;
};

/**
 * 扩展treegrid，使其支持平滑数据格式
 */
$.fn.treegrid.defaults.loadFilter = function (data, parentId) {
    var opt = $(this).data().treegrid.options;
    var idFiled, textFiled, parentField;
    if (opt.parentField) {
        idFiled = opt.idFiled || 'id';
        textFiled = opt.textFiled || 'text';
        parentField = opt.parentField;
        iconCls = opt.iconCls || 'iconCls';
        var i, l, treeData = [],
			tmpMap = [];
        for (i = 0, l = data.length; i < l; i++) {
            tmpMap[data[i][idFiled]] = data[i];
        }
        for (i = 0, l = data.length; i < l; i++) {
            if (tmpMap[data[i][parentField]] && data[i][idFiled] != data[i][parentField]) {
                if (!tmpMap[data[i][parentField]]['children'])
                    tmpMap[data[i][parentField]]['children'] = [];
                data[i]['text'] = data[i][textFiled];
                data[i]['iconCls'] = data[i][iconCls];
                tmpMap[data[i][parentField]]['children'].push(data[i]);
            } else {
                data[i]['text'] = data[i][textFiled];
                data[i]['iconCls'] = data[i][iconCls];
                treeData.push(data[i]);
            }
        }
        return treeData;
    }
    return data;
};

/**
 * 扩展combotree，使其支持平滑数据格式
 */
$.fn.combotree.defaults.loadFilter = $.fn.tree.defaults.loadFilter;


/*easyui样式初始化*/
$.fn.tabs.defaults.tabHeight = 32; //tab标签条高度
$.fn.linkbutton.defaults.height = 32; //按钮高度
$.fn.menu.defaults.itemHeight = 28; //menu高度

$.fn.validatebox.defaults.height = 32;
$.fn.textbox.defaults.height = 32;
$.fn.textbox.defaults.iconWidth = 24;
$.fn.datebox.defaults.height = 32;
$.fn.numberspinner.defaults.height = 32;
$.fn.timespinner.defaults.height = 32;
$.fn.numberbox.defaults.height = 32;
$.fn.combobox.defaults.height = 32;
$.fn.combotree.defaults.height = 32;
$.fn.combogrid.defaults.height = 32;
$.fn.passwordbox.defaults.height = 32;
$.fn.filebox.defaults.height = 32;
$.fn.menu.defaults.noline = true
$.fn.progressbar.defaults.height = 18; //进度条
    (function ($) {
        $.fn.combotree.extensions = $.extend({}, $.fn.combotree.extensions); 
        var defaults = $.fn.combotree.extensions.defaults = { 
            showNullItem:false,
            loadFilter: function (data) { 
                console.log(this);
                //console.log(this.options);
                var options = $(this).tree("options");
                console.log(options);
                if (options.showNullItem) {
                    data.unshift({ "id": "0","text":"" });
                }
                return data;
            }
        };
         
        $.extend($.fn.combotree.defaults, defaults); 
    })(jQuery);